(function(window, document) {
	var maskShare = function(targetDom, options) {
		if(!(this instanceof maskShare))
		    return new maskShare(targetDom, options);
		
		this options = this.extend({
			imgSrc: "img/1.png"
		}, options);
		
		if((typeof targetDom) === "string"){
			this.targetDom = document.querySelector(targetDom);
		}else {
			this.targetDom = targetDom;
		}
		
		var boxDom = document.createElement("div");
		var imgDom = document.createElement("img");
		
		boxDom.style.cssText = "display: none;position: absolute;left: 0;top: 0;width: 100%;height: 100%;background-color: rgba(0,0,0,0.8);z-index: 9999;";
		imgDom.style.cssText = "margin-top: 20px;width: 100%;";
		
		if(this.options.boxDomStyle) {
			this.setStyle(boxDom, this.options.boxDomStyle);
		}
		if(this.options.imgDomStyle) {
			this.setStyle(imgDom, this.options.imgDomStyle);
		}
		
		imgDom.src = this.options.imgSrc;
		boxDom.appendChild(imgDom);
		this.boxDom = boxDom;
		
		this.init();
	};
	
	maskShare.prototype = {
		init: function() {
			this.event();
		},
		extend: function (obj1, obj2) {
			for(var k in obj2) {
				obj[k] = obj2[k];
			}
			return obj;
		},
		setStyle: function (dom, objStyle) {
			for(var k in objStyle){
				dom.style[k] = objStyle[k];
			}
		},
		event: function () {
			var _this = this;
			this.targetDom.addEventListener("click",function() {
				document.body.appendChild(_this.boxDom);
				_this.boxDom.style.display = "block";
				_this.options.open && _this.options.open();
			},false);
			
			this.boxDom.addEventListener("click",function () {
				this.style.display = "none";
				_this.options.close && _this.options.close();
			},false)
		}
	};
	window.maskShare = maskShare;
})(window, document)
